<template>
    <div class="order-success-container">
        <div class="content-wrapper">
            <div class="success-card" v-if="trade_id">
                <div class="success-animation">
                    <div class="success-icon">
                        <i class="el-icon-success"></i>
                    </div>
                    <div class="success-ripple"></div>
                </div>
                
                <div class="success-content">
                    <h2 class="success-title">支付成功！</h2>
                    <p class="success-message">恭喜您，订单已成功支付</p>
                    
                    <div class="order-details">
                        <div class="detail-item">
                            <span class="label">订单号：</span>
                            <span class="value">{{ order_id }}</span>
                        </div>
                        <div class="detail-item">
                            <span class="label">支付交易号：</span>
                            <span class="value">{{ trade_id }}</span>
                        </div>
                        <div class="detail-item">
                            <span class="label">支付时间：</span>
                            <span class="value">{{ currentTime }}</span>
                        </div>
                    </div>
                    
                    <div class="success-actions">
                        <el-button 
                            type="primary" 
                            size="large" 
                            @click="goToOrders"
                            class="view-orders-btn"
                        >
                            <i class="el-icon-s-order"></i>
                            查看我的订单
                        </el-button>
                        <el-button 
                            size="large" 
                            @click="goToShopping"
                            class="continue-shopping-btn"
                        >
                            <i class="el-icon-shopping-bag-1"></i>
                            继续购物
                        </el-button>
                    </div>
                </div>
            </div>
            
            <div class="loading-card" v-else>
                <div class="loading-content">
                    <el-icon class="loading-icon">
                        <Loading />
                    </el-icon>
                    <p>正在处理支付信息...</p>
                </div>
            </div>
            
            <div class="tips-section">
                <div class="tip-item">
                    <i class="el-icon-info"></i>
                    <span>订单信息已发送到您的邮箱，请注意查收</span>
                </div>
                <div class="tip-item">
                    <i class="el-icon-phone"></i>
                    <span>如有疑问，请联系客服：400-888-8888</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { changeOrder } from '@/api/shopping'
import { Loading } from '@element-plus/icons-vue'

const router = useRouter()

const order_id = ref('')
const trade_id = ref('')
const currentTime = ref('')

// 获取当前时间
const getCurrentTime = () => {
    const now = new Date()
    currentTime.value = now.toLocaleString('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit'
    })
}

onMounted(() => {
    getCurrentTime()
    
    // 处理支付回调
    changeOrder(document.location.search).then(
        data => {
            console.log('支付成功', data)
            order_id.value = data.order_id
            trade_id.value = data.trade_id
        },
        error => {
            console.log('处理支付信息失败', error.message)
            // 可以跳转到错误页面或显示错误信息
        }
    )
})

// 跳转到订单页面
const goToOrders = () => {
    router.push('/user/order')
}

// 继续购物
const goToShopping = () => {
    router.push('/shopping')
}
</script>

<style lang="less" scoped>
.order-success-container {
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.content-wrapper {
    max-width: 600px;
    width: 100%;
}

.success-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 50px 40px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
    
    .success-animation {
        position: relative;
        margin-bottom: 30px;
        
        .success-icon {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: linear-gradient(45deg, #2ed573, #7bed9f);
            margin: 0 auto 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            z-index: 2;
            animation: successBounce 0.6s ease-out;
            
            i {
                font-size: 40px;
                color: white;
            }
        }
        
        .success-ripple {
            position: absolute;
            top: 50%;
            left: 50%;
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: rgba(46, 213, 115, 0.3);
            transform: translate(-50%, -50%);
            animation: ripple 2s infinite;
        }
    }
    
    .success-content {
        .success-title {
            font-size: 28px;
            color: #333;
            margin-bottom: 10px;
            font-weight: 700;
        }
        
        .success-message {
            font-size: 16px;
            color: #666;
            margin-bottom: 30px;
        }
        
        .order-details {
            background: rgba(102, 126, 234, 0.05);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 30px;
            
            .detail-item {
                display: flex;
                justify-content: space-between;
                margin-bottom: 12px;
                
                &:last-child {
                    margin-bottom: 0;
                }
                
                .label {
                    color: #666;
                    font-weight: 500;
                }
                
                .value {
                    color: #333;
                    font-weight: 600;
                }
            }
        }
        
        .success-actions {
            display: flex;
            gap: 15px;
            justify-content: center;
            
            .el-button {
                padding: 12px 25px;
                border-radius: 25px;
                font-size: 16px;
                font-weight: 500;
                transition: all 0.3s ease;
                
                &:hover {
                    transform: translateY(-2px);
                    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
                }
            }
            
            .view-orders-btn {
                background: linear-gradient(45deg, #667eea, #764ba2);
                border: none;
            }
            
            .continue-shopping-btn {
                background: rgba(102, 126, 234, 0.1);
                border: 1px solid rgba(102, 126, 234, 0.3);
                color: #667eea;
                
                &:hover {
                    background: rgba(102, 126, 234, 0.15);
                }
            }
        }
    }
}

.loading-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 50px 40px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    
    .loading-content {
        .loading-icon {
            font-size: 40px;
            color: #667eea;
            margin-bottom: 20px;
            animation: spin 1s linear infinite;
        }
        
        p {
            font-size: 16px;
            color: #666;
            margin: 0;
        }
    }
}

.tips-section {
    margin-top: 30px;
    
    .tip-item {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 10px;
        color: rgba(255, 255, 255, 0.9);
        font-size: 14px;
        
        i {
            margin-right: 8px;
            font-size: 16px;
        }
    }
}

@keyframes successBounce {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes ripple {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

// 响应式设计
@media (max-width: 768px) {
    .order-success-container {
        padding: 10px;
    }
    
    .success-card,
    .loading-card {
        padding: 30px 20px;
    }
    
    .success-card {
        .success-content {
            .success-title {
                font-size: 24px;
            }
            
            .success-actions {
                flex-direction: column;
                
                .el-button {
                    width: 100%;
                }
            }
        }
    }
}
</style> 